package bgu.gaoxu.diary.utils;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.xuexiang.xui.widget.textview.MarqueeTextView;

import bgu.gaoxu.diary.R;

/**
 * Created by GA666666 on 2021/5/14 11:41
 */
public class BeautyUtil {
    private static FrameLayout frameLayout;
    private static RelativeLayout top_layout;
    private static LinearLayout bottom_layout;
    private static MarqueeTextView marqueeTextView;
    private static View view;
    private static ImageButton btn_search, btn_index, btn_diary, btn_message, btn_myself, btn_menu;
    private static Activity context;

    public static void setBeauty(Activity activity) {

    }

    public static void setBeauty(Activity activity, int top_bottom_color, int fragmentbg_color) {
        init_layout(activity);
        setColor(frameLayout, fragmentbg_color);
        setColor(btn_index, top_bottom_color);
        setColor(btn_diary, top_bottom_color);
        setColor(btn_message, top_bottom_color);
        setColor(btn_myself, top_bottom_color);
        setColor(btn_search, top_bottom_color);
        setColor(btn_menu, top_bottom_color);
        setColor(marqueeTextView, top_bottom_color);
        setColor(top_layout, top_bottom_color);
        setColor(bottom_layout, top_bottom_color);
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, top_bottom_color));
        SharedPreferences sharedPreferences = context.getSharedPreferences("beauty_info", 0);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("color", true);
        editor.putInt("top_color", top_bottom_color);
        editor.putInt("bottom_color", top_bottom_color);
        editor.putBoolean("fragment", true);
        editor.putInt("fragment_myself", fragmentbg_color);
        editor.putInt("fragment_message", fragmentbg_color);
        editor.putInt("fragment_diary", fragmentbg_color);
        editor.apply();
    }

    public static void setImage(Activity activity) {
        init_layout(activity);
        setColor(frameLayout, R.color.white);
        SharedPreferences sharedPreferences = activity.getSharedPreferences("beauty_info", 0);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("color", false);
        editor.putBoolean("fragment", false);
        editor.apply();
    }

    public static void setFragment(Activity activity,View fLayout,int fragment_bg){
        init_layout(activity);
        Drawable back = activity.getDrawable(fragment_bg);
        SharedPreferences sharedPreferences = activity.getSharedPreferences("beauty_info", 0);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("fragment_bg", fragment_bg);
        editor.apply();
        fLayout.setBackground(back);
    }
    public static void setTop(Activity activity, int top_img) {
        init_layout(activity);
        Drawable back = activity.getDrawable(top_img);
        top_layout.setBackground(back);
        setColor(btn_menu, R.color.transparent);
        setColor(btn_search, R.color.transparent);
        setColor(marqueeTextView, R.color.transparent);
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, R.color.white));
    }

    public static void setBottom(Activity activity, int top_img) {
        init_layout(activity);
        Drawable back = activity.getDrawable(top_img);
        bottom_layout.setBackground(back);
        setColor(btn_index, R.color.transparent);
        setColor(btn_diary, R.color.transparent);
        setColor(btn_message, R.color.transparent);
        setColor(btn_myself, R.color.transparent);
    }

    public static void setTopColor(Activity activity, int top_color) {
        init_layout(activity);
        setColor(top_layout, top_color);
        activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, top_color));
    }

    public static void setBottomColor(Activity activity, int bottom_color) {
        init_layout(activity);
        setColor(bottom_layout, bottom_color);
    }

    public static void setFragmentColor(Activity activity, int fragmentbg_color) {
        init_layout(activity);
        setColor(frameLayout, fragmentbg_color);
    }

    public static void setFragmentColor(View view, int fragmentbg_color) {
        setColor(view, fragmentbg_color);
    }

    private static void init_layout(Activity activity) {
        context = activity;
        frameLayout = activity.findViewById(R.id.myself_layout);
        btn_search = activity.findViewById(R.id.btn_search);
        bottom_layout = activity.findViewById(R.id.bottom_layout);
        btn_menu = activity.findViewById(R.id.btn_menu);
        top_layout = activity.findViewById(R.id.top_layout);
        marqueeTextView = activity.findViewById(R.id.tv_marquee);
        btn_index = activity.findViewById(R.id.myhome);
        btn_diary = activity.findViewById(R.id.rv_mydiarylist);
        btn_message = activity.findViewById(R.id.mymessage);
        btn_myself = activity.findViewById(R.id.myself);
    }

    private static void setColor(View view, int color) {
        view.setBackgroundColor(context.getResources().getColor(color));
    }
}
